//
//  MXGesturesCell.m
//  MXLoginMethodsDomo
//
//  Created by 马彦 on 16/9/27.
//  Copyright © 2016年 MX. All rights reserved.
//

#import "MXGesturesCell.h"
#import "MXGesturesModel.h"
#import "MXGresturesSwitchModel.h"
#import "MXGresturesArrowModel.h"
#import "MXLockPassword.h"

@interface MXGesturesCell ()

/**
 标题
 */
@property (nonatomic, strong) UILabel *grestureLbl;
/**UIswitch*/
@property (nonatomic, strong) UISwitch *grestureSwitch;
/**箭头*/
@property (nonatomic, strong) UIImageView *arrowImgView;

@end

@implementation MXGesturesCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configureUI];
    }
    return self;
}


- (void)configureUI {
    UILabel *grestureLbl = [[UILabel alloc] init];
    grestureLbl.textColor = [UIColor blackColor];
    grestureLbl.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:grestureLbl];
    self.grestureLbl = grestureLbl;
    
}


- (void)grestureSwitchOnAction:(UISwitch *)swit {
   
   
    if ([_delegate respondsToSelector:@selector(gesturesWithSwitch:)]) {
        [_delegate gesturesWithSwitch:swit];
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
     
    [self.grestureLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.height.mas_equalTo(14);
    }];
  
}

- (void)setModel:(MXGesturesModel *)model {
    _model = model;
    
    self.grestureLbl.text = model.titleStr;
   
    if ([MXLockPassword oldPassword]) {
        self.grestureSwitch.on = YES;
    } else {
        
        self.grestureSwitch.on = NO;
    }
    
    if ([_model isKindOfClass:[MXGresturesArrowModel class]]) {

        self.accessoryView = self.arrowImgView;
        
    } else if ([_model isKindOfClass:[MXGresturesSwitchModel class]]) {
        self.accessoryView = self.grestureSwitch;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
 
}

- (UIImageView *)arrowImgView {
    if (!_arrowImgView) {
        _arrowImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rightArrow"]];
    }
    return _arrowImgView;
}

- (UISwitch *)grestureSwitch {
    if (!_grestureSwitch) {
        _grestureSwitch = [[UISwitch alloc] init];
        _grestureSwitch.tintColor = RGBA_Color(0.75, 0.75, 0.75, 1.0);
        _grestureSwitch.onTintColor = RGBA_Color(0.55, 0.40, 0.78, 1.0);
        [_grestureSwitch addTarget:self action:@selector(grestureSwitchOnAction:) forControlEvents:UIControlEventValueChanged];
    }
    return _grestureSwitch;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
